package 数组;

import java.util.ArrayList;

public class 顺时针旋转矩阵 {
    public int[][] rotateMatrix(int[][] mat, int n) {
        //先将上下两行交换
        for (int i = 0; i < n; i++) {
            int tmp[] = mat[i];
           mat[i] = mat[n-i-1];
           mat[n-i-1] = tmp;
        }
        //再按对角线交换
        for (int i = 0; i < n; i++) {
            for (int j = i+1; j < n; j++) {
                int tmp = mat[i][j];
                mat[i][j] = mat[j][i];
                mat[j][i] = tmp;
            }
        }
        return mat;

    }
}
